import request from './request'

/**
 * 历史记录接口定义
 */
export interface HistoryRecord {
  id: number;
  title: string;
  description: string;
  status: 'completed' | 'pending' | 'failed';
  type: string;
  timestamp: string;
  canReplay: boolean;
}

/**
 * 获取历史记录列表
 * @returns 历史记录列表
 */
export async function getHistoryRecords(): Promise<HistoryRecord[]> {
  try {
    const response = await request.get('/v1/history/')
    return ((response as unknown as any).histories || []) as HistoryRecord[]
  } catch (error) {
    console.error('获取历史记录失败:', error)
    throw error
  }
}

/**
 * 删除历史记录
 * @param recordId 记录ID
 * @returns 删除操作结果
 */
export async function deleteHistoryRecord(recordId: number): Promise<boolean> {
  try {
    await request.delete(`/v1/history/${recordId}`)
    return true
  } catch (error) {
    console.error('删除历史记录失败:', error)
    throw error
  }
}

/**
 * 清空所有历史记录
 * @returns 清空操作结果
 */
export async function clearAllHistoryRecords(): Promise<boolean> {
  try {
    const response = await request.delete('/v1/history/all')
    return !!response
  } catch (error) {
    console.error('清空历史记录失败:', error)
    throw error
  }
}
